#include <stdio.h>
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>

option longOpt[] = {
    {"file",    required_argument, NULL, 'f'},
    {"out",     required_argument, NULL, 'o'},
    {"help",    no_argument,       NULL, 'h'},
    {"version", no_argument,       NULL, 'v'},
    {NULL,      no_argument,       NULL, 0}
};
static const char *optString = "f:o:hv";
void usage(char* proName) {
    printf("usage: %s option argument\n", proName);
    printf("       -f --file [file name] get the input file name.\n");
    printf("       -o --out  [file name] put the output to file name.\n");
    printf("       -h --help get this help information.\n");
    printf("       -v --version get the version of this program.\n");
    exit(0);
}
struct Config {
    std::string inputFile;
    std::string outputFile;
};
int main(int argc, char** argv) {
    int opt, longIndex;
    Config config;
    opt = getopt_long(argc, argv, optString, longOpt, &longIndex);
    if (opt == -1) {
        usage(argv[0]);
    }
    while (opt != -1) {
        switch(opt) {
            case 'f':
                config.inputFile = optarg;
                break;
            case 'o':
                config.outputFile = optarg;
                break;
            case 'v':
                printf("This program is %s 1.0beta.\n", argv[0]);
                break;
            case 'h':
            case 0:
            default:
                usage(argv[0]);
                break;
        }
        opt = getopt_long(argc, argv, optString, longOpt, &longIndex);
    }
    printf("inputFile of config is %s.\n",  config.inputFile.c_str());
    printf("outputFIle of config is %s.\n", config.outputFile.c_str());
    return 0;
}
